import axios from 'axios'

export default {

    // 登录
    login(data){
        return axios({
            method: 'post',
            url: '/login',
            data: data,
            // 模仿表单提交
            transformRequest: [
                function (data) {
                    let ret = ''
                    for (let it in data) {
                        ret +=
                            encodeURIComponent(it) +
                            '=' +
                            encodeURIComponent(data[it]) +
                            '&'
                    }
                    return ret
                }
            ],
            headers:{
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        })
    },

    // 退出登录
    logout(){
        return axios({
            method: 'get',
            url: '/logout',
        })
    },

    // 查询用户信息
    getUserList(data){
        return axios({
            method: 'get',
            url: '/user/getUserList',
            params: data
        })
    },

    // 新增用户信息
    addUser(data){
        return axios({
            method: 'post',
            url: '/user/addUser',
            data: data
        })
    },

    // 修改用户信息
    updateUser(data){
        return axios({
            method: 'put',
            url: '/user/updateUser',
            data: data
        })
    },

    // 删除用户信息
    deleteUser(data){
        return axios({
            method: 'delete',
            url: '/user/deleteUser',
            params: data
        })
    }
}
